from asyncio import get_event_loop


def fetch(url):
    request = AsyncRequest('www.baidu.com', url, 80)
    data = yield from request.process()
    return data


def get_page(url):
    page = yield from fetch(url)
    return page


def async_way():
    ev_loop = get_event_loop()
    ev_loop.run_until_complete([
        get_page('/s?wd={}'.format(i)) for i in range(100)
    ])


from time import time

start = time()

async_way()  # Cost 3.534296989440918 seconds

end = time()
print('Cost {} seconds'.format(end - start))
